<template>
  <LayoutWrap :isExpand="isExpand" class="flex flex-1">
    <template #left v-if="!isExpand"> <Left></Left></template>
    <template #centerTop
      ><CenterTop
        :style="centerTopStyle"
        v-model:value="measureInfo"
      ></CenterTop
    ></template>
    <template #right v-if="!isExpand"><Right></Right></template>
  </LayoutWrap>
</template>
<route lang="json">
{
  "name": "screen2d",
  "meta": { "title": "数智大屏", "requireAuth": false, "layout": false }
}
</route>
<script setup lang="tsx">
import { computed, ref, watch } from 'vue';
import { eventBus } from '@/utils/eventMitt';
import { getScene2dPreviewDetail } from '../../api';
import LayoutWrap from './components/LayoutWrap.vue';
import Left from './components/left/index.vue';
import Right from './components/right/index.vue';
import CenterTop from './components/scene2/center-top/index.vue';

const props = defineProps({
  isExpand: {
    type: Boolean,
    default: false,
  },
});

// 根据中间图缩放样式不同
const centerTopStyle = computed(() => {
  return {
    margin: !props.isExpand ? '0 18px' : '0',
    width: !props.isExpand ? 'calc(100% - 36px)' : '100%',
    height: '100%',
  };
});

// 测点详情（包括监测阵id）
const measureInfo = ref<any>({});
const structureId = ref<string>(history.state.structureId || '');
// 监听左侧下拉框变化:重新获取测点信息
eventBus.on('changeStructure', (data: any) => {
  structureId.value = data.structureId;
});

// 初始进入二维场景展示波形数据
const init = async () => {
  // 获取测点详情
  const pointRes = await getScene2dPreviewDetail({
    structureId: structureId.value,
  });
  measureInfo.value = pointRes.data?.[0];
};
init();
watch(
  () => structureId.value,
  () => {
    init();
  },
);
</script>

<style lang="scss" scoped></style>
